package com.java.clone;

import org.junit.Test;

import java.io.IOException;

public class Client {
	public static void main(String[] args){
		Apple apple = new Apple();
		apple.setColor("blue");
		apple.setPrice(8.7);
		AppleType type = new AppleType();
		type.setType("红富士");
		apple.setType(type);
		Apple apple1 = null;
		try {
			apple1 = (Apple)apple.clone();
		} catch (CloneNotSupportedException e) {
			e.printStackTrace();
		}
		System.out.println(apple1 == apple);
		apple1.setColor("yellow");

		System.out.println(apple1);

		System.out.println(apple);
	}

	@Test
	public void depthClone() throws IOException, ClassNotFoundException {
		OrangeType t = new OrangeType();
		t.setType("芦柑");
		OrangeType t2 = new OrangeType();
		t.setType("测试");

		Orange o = new Orange();
		o.setColor("yellow");
		o.setPrice(55);
		o.setType(t);
		o.setType2(t2);

		Orange o2 = o.depthClone();
		o2.setColor("blue");
		o2.getType().setType("柑橘");

		System.out.println(o);
		System.out.println(o2);
	}
}
